//
//  SeizureLog.m
//  Seizure
//
//  Created by student on 2/21/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "EventLog.h"

@implementation EventLog

NSString * const START_TIME_ENCODE = @"startTime";
NSString * const END_TIME_ENCODE = @"endTime";
NSString * const LOCATION_ENCODE = @"location";

@synthesize startTime;
@synthesize endTime;
@synthesize locationOfEvent;

- (id)init:(NSDate *)start end:(NSDate *)end location:(CLLocation *)loc
{
    if(self == [super init])
    {
        startTime = start;
        endTime = end;
        locationOfEvent = loc;
    }
    return self;
}

/**
 * Returns the interval of time between the start time and end time of this event in seconds.
 */
- (NSTimeInterval)getEventLength
{
    NSTimeInterval elapsedTime = [endTime timeIntervalSinceDate:startTime];
    return elapsedTime;
}


#pragma mark -- NSCODING PROTOCOL METHODS

/**
 * Returns an object initialized from data in a given unarchiver.
 */
- (id)initWithCoder:(NSCoder *)decoder
{
    startTime = [decoder decodeObjectForKey:START_TIME_ENCODE];
    endTime = [decoder decodeObjectForKey:END_TIME_ENCODE];
    locationOfEvent = [decoder decodeObjectForKey:LOCATION_ENCODE];
    
    return self;
}

/**
 * Encodes the receiver using a given archiver. 
 */
-(void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:startTime forKey:START_TIME_ENCODE];
    [encoder encodeObject:endTime forKey:END_TIME_ENCODE];
    [encoder encodeObject:locationOfEvent forKey:LOCATION_ENCODE];
}

@end
